/* eslint-disable @typescript-eslint/no-explicit-any */
/**
 * @template {number} T
 * @param {number[]} arr
 * @returns {[number, ...number[]]}
 */
function prefixSum<const T extends number, const U extends number[] | []>(
  arr: U,
  init: T = 0 as T,
): [init: T, ...U] {
  return arr.reduce<number[]>(
    ((prev: [T, ...U], cur: number) => [...prev, cur + prev.at(-1)!]) as any,
    [init] as [init: T],
  ) as [init: T, ...U];
}

prefixSum([1, 2, 3]);
